/**
 * 全局样式
 * 包含基础元素样式、常用工具类等
 */

// 使用现代的 Sass 模块系统
@use './mixins.scss' as mixins;
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--gray-1);
  background-color: var(--gray-7);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

a {
  color: var(--brand-1);
  text-decoration: none;
  transition: all 0.2s ease;

  &:hover {
    color: var(--brand-2);
    text-decoration: none;
  }

  &:focus {
    outline: 2px solid var(--brand-4);
    outline-offset: 2px;
  }
}

img {
  max-width: 100%;
  height: auto;
}

/* 容器 */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* 工具类 */
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
}

.gap-4 {
  gap: 1rem;
}

.gap-8 {
  gap: 2rem;
}

.gap-12 {
  gap: 3rem;
}

.mx-auto {
  margin-left: auto;
  margin-right: auto;
}

.my-4 {
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.my-8 {
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-4 {
  margin-top: 1rem;
}

.mt-8 {
  margin-top: 2rem;
}

.mt-12 {
  margin-top: 3rem;
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mb-8 {
  margin-bottom: 2rem;
}

.mb-12 {
  margin-bottom: 3rem;
}

.p-4 {
  padding: 1rem;
}

.p-6 {
  padding: 1.5rem;
}

.p-8 {
  padding: 2rem;
}

.px-4 {
  padding-left: 1rem;
  padding-right: 1rem;
}

.py-2 {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.py-4 {
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.py-8 {
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.py-12 {
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.py-20 {
  padding-top: 5rem;
  padding-bottom: 5rem;
}

.rounded-lg {
  border-radius: var(--radius-lg);
}

.shadow-sm {
  box-shadow: var(--shadow-1);
}

.shadow-md {
  box-shadow: var(--shadow-2);
}

.shadow-lg {
  box-shadow: var(--shadow-3);
}

.bg-white {
  background-color: var(--white);
}

.bg-gray-7 {
  background-color: var(--gray-7);
}

.text-gray-1 {
  color: var(--gray-1);
}

.text-gray-2 {
  color: var(--gray-2);
}

.text-gray-3 {
  color: var(--gray-3);
}

.border {
  border: 1px solid var(--gray-6);
}

.border-t {
  border-top: 1px solid var(--gray-6);
}

.border-b {
  border-bottom: 1px solid var(--gray-6);
}

.border-gray-5 {
  border-color: var(--gray-5);
}

.border-gray-6 {
  border-color: var(--gray-6);
}

/* 响应式工具类 */
@media (min-width: 768px) {
  .md\:flex {
    display: flex;
  }

  .md\:flex-row {
    flex-direction: row;
  }

  .md\:w-1\/2 {
    width: 50%;
  }

  .md\:w-1\/3 {
    width: 33.333333%;
  }

  .md\:w-2\/3 {
    width: 66.666667%;
  }

  .md\:w-1\/4 {
    width: 25%;
  }

  .md\:w-3\/4 {
    width: 75%;
  }

  .md\:space-x-8 > * + * {
    margin-left: 2rem;
  }

  .md\:hidden {
    display: none;
  }

  .md\:text-left {
    text-align: left;
  }

  .md\:mb-0 {
    margin-bottom: 0;
  }
}

@media (min-width: 1024px) {
  .lg\:flex {
    display: flex;
  }

  .lg\:flex-row {
    flex-direction: row;
  }

  .lg\:w-64 {
    width: 16rem;
  }

  .lg\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* 网格系统 */
.grid {
  display: grid;
}

.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

@media (min-width: 768px) {
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .md\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* 图标 */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  border: none;
  font-size: 1rem;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    transition: background-color 0.3s ease;
  }

  &:hover::before {
    background-color: rgba(255, 255, 255, 0.1);
  }

  &:active {
    transform: translateY(1px);
  }

  &:focus {
    outline: 2px solid var(--brand-4);
    outline-offset: 2px;
  }

  &-primary {
    background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
    color: white;
    box-shadow: 0 4px 10px rgba(var(--brand-1-rgb), 0.2);

    &:hover {
      box-shadow: 0 6px 15px rgba(var(--brand-1-rgb), 0.3);
    }
  }

  &-outline {
    background-color: transparent;
    color: var(--gray-1);
    border: 1px solid var(--gray-5);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);

    &:hover {
      border-color: var(--brand-1);
      color: var(--brand-1);
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    }
  }
}

/* 表单元素 */
@mixin form-element-base {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-5);
  border-radius: 8px;
  background-color: var(--white);
  color: var(--gray-1);
  font-size: var(--font-size-md);
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);

  &:hover {
    border-color: var(--gray-4);
  }

  &:focus {
    outline: none;
    border-color: var(--brand-1);
    box-shadow: var(--shadow-focus);
  }

  &::placeholder {
    color: var(--gray-4);
    opacity: 1;
  }
}

input, textarea, select {
  @include form-element-base;
}

/* 老年模式 */
.elder-mode {
  font-size: 18px;

  input,
  button,
  textarea,
  select {
    font-size: 18px;
  }
}

/* 暗色模式切换 */
.color-scheme-toggle {
  @include mixins.flex(row, center, center);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--gray-7);
  color: var(--gray-2);
  cursor: pointer;
  @include mixins.transition;

  &:hover {
    background-color: var(--gray-6);
    color: var(--gray-1);
  }
}
